if (islogin()) {
    var data1;
    $.post({
        url:'../../requests/teacher/select_leavemessage.php',
        async:false,
        success:function (data) {
            data1=data;
            console.log(data);
            for (var i = 0; i < data.length; i++) {
                if (data[i].reply) {
                    var dom =" <div class=\"content-block-title\">班级:"+data[i].class+" 学生:"+data[i].stu_name+" "+data[i].student+"</div>\n" +
                        "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">标题:"+data[i].title+"</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">\n" + data[i].detail+
                        "                        </div>\n" +
                                            "</div>\n" +
                        "                        <div class=\"card-footer\">\n" +
                        "                            <span>"+data[i].time+"</span>\n" +
                        "                            <span><button class=\"button disabled\">已回复</button></span>\n" +
                        "                        </div>\n" +
                        "                </div>\n" +
                        "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">回复内容</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">"+data[i].reply+"</div>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"card-footer\">\n" +
                        "                        <span>"+data[i].re_time+"</span>\n" +
                        "                    </div>\n" +
                        "                </div>";
                }
                else {
                    var dom=" <div class=\"content-block-title\">班级:"+data[i].class+" 学生:"+data[i].stu_name+" "+data[i].student+"</div>\n" +
                        "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">标题:"+data[i].title+"</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">\n" + data[i].detail+
                        "                        </div>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"card-footer\">\n" +
                        "                        <span>"+data[i].time+"</span>\n" +
                        "                        <span><button class=\"button btn_reply btn_"+data[i].Id+"\">回复</button></span>\n" +
                        "                    </div>\n" +
                        "                </div>\n"
                }
                $('.cards-list').append(dom);
            }
        }
    });

    $('.cards-list').on('click','.btn_reply',function () {
        var id=$(this).attr('class').split(' ')[2].split('_')[1];
        $$.modal({
            title:'回复',
            text:'请在下方输入回复内容',
            afterText:"<textarea rows='8' class='re_text'></textarea>",
            buttons:[
                {
                    text:'取消'
                },
                {
                    text:'回复',
                    onClick:function () {
                        var re_text=$('.re_text').val();
                        if (!re_text) {
                            $$.alert("回复内容不能为空！");
                        }
                        else {
                            $.post({
                                url:'../../requests/teacher/reply.php',
                                data:{'leavemsg':id,'detail':re_text},
                                success:function (data) {
                                    if (data == '1'){
                                        $$.alert('回复成功！',function () {
                                            location.reload(true);
                                        });
                                    }
                                    else $$.alert('回复失败！');
                                }
                            });
                        }
                    }
                }
            ]
        });
    });
}
else window.location.href='../../index.html';